import os
from pathlib import Path

class Config:
    # 基础配置
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'your-secret-key-here-change-in-production'
    
    # 项目根目录
    BASE_DIR = Path(__file__).resolve().parent
    
    # 数据库配置
    DATABASE_PATH = BASE_DIR / 'database.db'
    SQLALCHEMY_DATABASE_URI = f'sqlite:///{DATABASE_PATH}'
    SQLALCHEMY_TRACK_MODIFICATIONS = False
    
    # 文件上传配置
    UPLOAD_FOLDER = BASE_DIR / 'uploads'
    EXPORT_FOLDER = BASE_DIR / 'exports'
    MAX_CONTENT_LENGTH = None  # 移除文件大小限制，支持大TIF文件
    
    # 允许的文件扩展名
    ALLOWED_IMAGE_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif', 'tif', 'tiff', 'webp', 'psd', 'psb'}
    ALLOWED_JSON_EXTENSIONS = {'json'}
    
    # 创建必要的目录
    @classmethod
    def init_app(cls):
        cls.UPLOAD_FOLDER.mkdir(exist_ok=True)
        cls.EXPORT_FOLDER.mkdir(exist_ok=True)
        (cls.BASE_DIR / 'static' / 'images').mkdir(parents=True, exist_ok=True)
